package com.qf.service.impl;

import com.qf.dao.AddressDao;
import com.qf.dao.impl.AddressDaoImpl;
import com.qf.entity.Address;
import com.qf.service.AddressService;
import com.qf.utils.DruidUtils;

import java.util.List;

/**
 * @author 10202
 * @version V1.0
 * @Project xiaomi
 * @Package com.qf.service.impl
 * @Date 2023/4/14 21:20
 */
public class AddressServiceImpl implements AddressService {
    AddressDao addressDao=new AddressDaoImpl();
    @Override
    public List<Address> queryAddressByUid(Integer id) {
        return addressDao.queryAddressByUid(id);
    }

    @Override
    public void addAddress(Address address) {
        addressDao.addAddress(address);
    }

    @Override
    public void deleteAddressById(int intId) {
        addressDao.deleteAddressById(intId);
    }

    @Override
    public void updateAddress(Address address) {
        addressDao.updateAddress(address);
    }

    @Override
    public void updateAddressAllLevel(int uid) {

        addressDao.updateAddressAllLevel(uid);

    }

    @Override
    public void updateAddressLevel(int id,int uid) {
        try {
            //事务
            DruidUtils.begin();
            //1.清空标记
            AddressService addressService=new AddressServiceImpl();
            addressService.updateAddressAllLevel(uid);

            //2.设置默认
            addressDao.updateAddressLevel(id);
            DruidUtils.commit();
        } catch (Exception e) {
            DruidUtils.rollback();
           throw new RuntimeException(e);
        }finally {
            DruidUtils.close();
        }

    }


}
